<template>
	<view class="page-form">
		<view class="atitle">
			选择查找条件
		</view>
		<form @submit="formSubmit" @reset="formReset">
			<view class="pageblock">
				<view class="cu-form-group">
					<view class="title">类型</view>
					<picker @change="leixingChange" :value="0" :range="pram_locadata.danPicker">
						<view class="picker">
							{{pram_locadata.danPicker[pram_form.leixing]}}
						</view>
					</picker>
				</view>
				<view class="cu-form-group">
					<view class="title">出发地</view>
					<input placeholder="选择出发位置" name="qidian" :value="pram_form.qidian"></input>
					<text class='cuIcon-locationfill text-orange'></text>
				</view>
				<view class="cu-form-group">
					<view class="title">目的地</view>
					<input placeholder="请选择目的地" name="zhongdian" :value="pram_form.zhongdian"></input>
					<text class='cuIcon-locationfill text-orange'></text>
				</view>
				<view class="cu-form-group">
					<view class="title">出发日期</view>
					<picker mode="date" :value="pram_form.chufa_date" start="2019-10-1" end="2022-10-1" @change="DateChange">
						<view class="picker">
							{{pram_form.chufa_date}}
						</view>
					</picker>
				</view>
				<view class="cu-form-group">
					<view class="title">出发时间</view>
					<picker mode="time" :value="pram_form.chufa_time" start="05:01" end="24:59" @change="TimeChange">
						<view class="picker">
							{{pram_form.chufa_time}}
						</view>
					</picker>
				</view>
			</view>
			<view class="margin-top">
				<button class="btnsubmit" type="primary" form-type="submit">确认</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				api_url: '',
				pram_locadata: {
					danPicker: ['全部', '人找车', '车找人', '车找货', '货找车'],
				},
				pram_form: {
					qidian: '',
					zhongdian: '',
					chufa_time: '09-01',
					chufa_date: '2019-10-01',
					leixing: '0',
				}
			}
		},

		onLoad() {
			var date = new Date();
			var Y = date.getFullYear();
			var m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
			var d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
			var H = date.getHours()
			var i = date.getMinutes()
			var s = date.getSeconds()
			this.pram_form.chufa_date = Y + '-' + m + '-' + d
			this.pram_form.chufa_time = H + ':' + i
		},

		methods: {
			formSubmit: function(e) {
				var formdata = e.detail.value
				this.pram_form.qidian = formdata.qidian
				this.pram_form.zhongdian = formdata.zhongdian
				this.http.post(this.api_url, this.pram_form).then(res => {
					res = res.data
					if(res.code == 200) {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						});
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					uni.showToast({
						title: '系统错误',
						icon: 'none',
						duration: 2000
					});
				})
			},
			leixingChange(e) {
				this.pram_form.leixing = e.detail.value
			},
			TimeChange(e) {
				this.pram_form.chufa_time = e.detail.value
			},
			DateChange(e) {
				this.pram_form.chufa_date = e.detail.value
			},
			mapXuan(type) {
				let that = this
				uni.chooseLocation({
				    success: function (res) {
						console.log(type)
						if(type === 1) {
							that.pram_form.qidian = res.address
						}
						if(type === 2) {
							that.pram_form.zhongdian = res.address
						}
				    }
				});
			}
		}
	}
</script>

<style lang="less">
	
</style>
